import random





bank_name='中国农业银行'
users={}
max_users=100
current_users=0
#定义地址，存钱，取钱，转账
def Address(country,province,street,door_number):                         #地址
    return {
        'country': country,
        'province': province,
        'street': street,
        'door_number': door_number
    }


def Username():                                           #账号
    username=str(random.randint(10000000, 99999999))
    if username not in users:
        return username



def open_account(type,name,password,address,money):                          #开户
    global current_users, users
    if current_users>=max_users:
        return 3
    for user in users.values():
        if user['name'] == name:
            return 2

    username =Username()
    new_user={'username':username,
             'type':type,
             'name':name,
             'password':password,
             'address':address,
             'money':money,
             'bank_name':bank_name
             }
    users[username]=new_user
    current_users+=1
    return 1
def inmoney(username,account):                             #存款
    if username not in users:
        return False
    else:
        users[username]['money']+=account
        return True

def outmoney(username,password,account):                             #取款
    if username not in users:
        return 1
    if users[username]['password']!=password:
        return 2
    if users[username]['money']<account:
        return 3
    users[username]['money']-=account
    return

def transport(rusername,lusernaem,password,acccount):                #转账
    if rusername not in users or lusernaem not in users:
        return 1
    if password !=users[rusername]['password']:
        return 2
    if acccount>=users[rusername]['money']:
        return 3
    users[rusername]['money']-=acccount
    users[lusernaem]['money']+=acccount
    return

def look_for(username,password):             #查询
    if username not in users:
        print('该用户不存在')
        return
    if password!=users[username]['password']:
        print('密码不对')
        return
    address_info = (
        f"{users['address']['country']}{users['address']['province']}"
        f"{users['address']['street']}{users['address']['door_number']}"
    )

    # 打印用户信息
    print(f"当前账号：{users['account_number']}, "
          f"密码：{users['password']:06d}, "
          f"余额：{users['balance']}元, "
          f"用户居住地址：{address_info}, "
          f"当前账户的开户行：{users['bank_name']}")
    return



def ATM():                                           #atm
    while True:
        print("\n" + "=" * 30)
        print("中国农业银行账户管理系统")
        print("=" * 30)
        print("1. 开户")
        print("2. 存钱")
        print("3. 取钱")
        print("4. 转账")
        print("5. 查询")
        print("6. 退出")
        print("=" * 30)

        choice = input("请输入业务编号: ")


        if choice == "1":
            do_open_account()
        elif choice == "2":
            do_inmoney()
        elif choice == "3":
            do_outmony()
        elif choice == "4":
            do_transport()
        elif choice == "5":
            do_look_for()
        elif choice == "6":
            print("感谢使用，再见！")
            break
        else:
            print("无效的选项，请重新输入！")





def do_open_account():                      #开户内容
    print("/n[开户服务]")
    type =int(input('请输入账号类型1.普通2.vip'))
    name = input("请输入姓名: ")
    password = int(input("请输入6位数字密码: "))

    # 地址信息
    print("\n请输入地址信息:")
    country = input("国家: ")
    province = input("省份: ")
    street = input("街道: ")
    door_number = input("门牌号: ")
    address = Address(country, province, street, door_number)

    money = int(input("请输入初始存款金额: "))

    # 调用开户函数
    result = open_account(type, name, password, address, money)
    if result ==1:
        print('成功')
    elif result==2:
        print(' 失败，账号已存在')
    elif result==3:
        print('失败，用户库已满')

def do_inmoney():
    print("/n[存款服务]")
    username=input('请输入账号')
    account=int(input('请输入存款金额'))
    if inmoney(username,account):
        print('存款成功，当前余额',users[username]['money'])
    else:
        print('存款失败')

def do_outmony():
    print("/n[取款服务]")
    username=input('请输入账号')
    password=int(input('请输入密码'))
    account=int(input('请输入金额'))

    result=outmoney(username,password,account)
    if result==1:
        print('账号不存在')
    if result==2:
        print('密码不对')
    if result==3:
        print('钱不够')
    if result==0:
        print('成功')

def do_transport():
    print("/n[转账服务]")
    rusername=input('请输入取出账户')
    lusername=input('请输入转入账户')
    password=int(input('请输入转出账户密码'))
    account=int(input('请输入金额'))
    result=transport(rusername,lusername,password,account)
    if result==0:
        print('正常')
    if result==1:
        print('账号不对')
    if result==2:
        print('密码不对')
    if result==3:
        print('钱不够')

def do_look_for():
    print("\n[查询业务]")
    account_number = input("请输入账号: ")
    password = int(input("请输入密码: "))

    look_for(account_number, password)

if __name__ == "__main__":
    ATM()








